Dynomotion

Group: DynoMotion Message: 11673 From: fouijar Date: 6/10/2015
Subject: M6 tool change, from Mach3 to KmotionCNC
Hello Tom,

Basically I would like to migrate from Mach3 to KmotionCNC, the last point I need to address is the tool change sequence. As shown into the attached files the flow chart is pretty straightforward and the old VB code has to be modified or translated to C.

I have begun with the M6.c code but I will need some help to figure out how to get/set information.
I do understand I'll use temporary and persistent variables to monitor the tool change status and tooling information.

What I would like to know, at first, is: what are the functions, variables names and locations?
I've checked the various .h and .c files, found some definitions and notions but I don't really understand how to make a good use of it.
ie: If the current tool ID is 32 and Slot# 8 and the next Tool ID is 2 and Slot# 2, what would be the practical code example (functions, variables etc.)
Are there some functions like GetSelectedTool(), GetCurrentTool ... ?

Based on the documents provided, would you please tell me you would handle that?

Regards,

Jerome


  @@attachment@@
Group: DynoMotion Message: 11873 From: fouijar Date: 7/8/2015
Subject: Re: M6 tool change, from Mach3 to KmotionCNC
Hello Tom,

Following my previous message I kept digging to better understand how to handle the tool change.
To illustrate, here is a working VB code sample that gives a status number depending on various parameters:

' Compare between actual tool and requested tool to decide the next sequence to choose
Function Compare() As Integer
    If (Newtool=99) Then 'Initialize Carousel To REF position => Tool index at 1
        Compare = -1
    ElseIf (Newtool=0) Then 'Empty spindle sequence
        Compare = 0
    ElseIf (NewTool = OldTool) Then 'Change the actual tool to the next used
        Compare = 2
    ElseIf (NewTool<>OldTool) Then
        Compare=1
    End If
End Function

I would like to execute the same decision using C and my problem is as described before, functions, variables and data location.
Here is a sample of what I did using information in various source files:

/*--------------------------------
------------Compare---------------
--------------------------------*/
//Compare between actual tool and requested tool to decide the sequence flow to choose.
int Compare()
{
    if (ReadBit(CarRef)&&tool_table_index=99)
        Compare=-1;
    else if (selected_tool_slot==current_slot&&tool==0)         //current_slot; carousel slot number of current tool
        Compare=4;
    else if (tool_id==0&&tool!=99)
        Compare=3;
    else if (tool==99)
        Compare=-1;
    else if (tool==0)
        Compare=0;
    else if (selected_tool_slot==current_slot&&==tool_id


Obviously, it doesn't work... That's why I coming back to you.

Would you give me your input?

Regards,

Jerome
Group: DynoMotion Message: 11874 From: fouijar Date: 7/8/2015
Subject: Re: M6 tool change, from Mach3 to KmotionCNC
Hi Tom,

I just sent a message that doesn't seem to appear, anyway...
Following my previous message I kept digging to better understand the information available in the source files to solve my tool change issue.

From my previous situation the working VB code sample below was:

' Compare between actual tool and requested tool to decide the next sequence to choose
Function Compare() As Integer
    If (Newtool=99) Then 'Initialize Carousel To REF position => Tool index at 1
        Compare = -1
    ElseIf (Newtool=0) Then 'Empty spindle sequence
        Compare = 0
    ElseIf (NewTool = OldTool) Then 'Change the actual tool to the next used
        Compare = 2
    ElseIf (NewTool<>OldTool) Then
        Compare=1
    End If
End Function

My actual C code sample is:

/*--------------------------------
------------Compare---------------
--------------------------------*/
//Compare between actual tool and requested tool to decide the sequence flow to choose.
int Compare()
{
    if (ReadBit(CarRef)&&tool_table_index=99)
        Compare=-1;
    else if (selected_tool_slot==current_slot&&tool==0)         //current_slot; carousel slot number of current tool
        Compare=4;
    else if (tool_id==0&&tool!=99)
        Compare=3;
    else if (tool==99)
        Compare=-1;
    else if (tool==0)
        Compare=0;
    else if (selected_tool_slot==current_slot&&==tool_id

This code doesn't work because I don't have the right functions, variables and data locations (except *.tbl file)
For reference I used the canon, driver, rs427ngc...files.

Would you please give me your input ?

Regards,

Jerome
Group: DynoMotion Message: 11875 From: Tom Kerekes Date: 7/8/2015
Subject: Re: M6 tool change, from Mach3 to KmotionCNC
Hi Jerome,

You seem to be missing the concept that KFLOP C programs run inside KFLOP not the PC.  The GCode Interpreter (canon, driver, rs427ngc...files) runs in the PC.  KFLOP C programs can not directly access memory variables in the PC.

Your original "Compare" function seems to be dependent on only two Variables NewTool and OldTool.  I'm not sure why your new code is involving like 7 different things including an input bit.

I'm assuming this C code will be invoked based on a GCode Tool Change Command such as:

M6T3

In this case the New Tool number of 3 will be downloaded to KFLOP and placed into a KFLOP persist Variable before your C program is invoked.  If you configure M6 to use Var 9 then the NewTool value will be placed in persist Variable #9 so you can retrieve it into a variable called NewTool with a C statement like

int NewTool = persist.UserData[9];

OldTool is always a problem with Tool Change Programs as what was the last tool loaded and other conditions must be maintained from one tool change to the next.  This is especially complicated when a power cycle might have occurred or something moved manually or removed by the operator and so forth.  I assume your M6T0 and M6T99 are meant to help with those cases.

Internal variables within a C program will not necessarily be maintained from one execution of the Program to the next.  So some persist Variable should be used to save and retrieve what the last tool was.  For example we might use Variable #12.  So we will assume the Last Tool was saved there and we can retrieve it with
int OldTool = persist.UserData[12];

If we decide to change tools or whatever we should update this variable when we are finished so it reflects the new state for any tool change that happens in the future.  With something like:

persist.UserData[12] = xxxxx;


Let me know how much of this makes sense.

Regards
TK